﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class rate_type : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.String _name;
private System.Int32? _val;
private IList<art_rate_type> _art_rate_types;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

public virtual System.String name 
{
get
{
return _name;
}
set 
{
if ( _name != value) 
{
_name = value ;
OnPropertyChanged("name");
}
}
}

public virtual System.Int32? val 
{
get
{
return _val;
}
set 
{
if ( _val != value) 
{
_val = value ;
OnPropertyChanged("val");
}
}
}

/// <summary>
/// Collection of art_rate_type.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "eba7c57a-c6e5-49a6-b18c-7d7a8a8f9f04" , CollectionOfType = typeof(art_rate_type)) ]
public virtual IList<art_rate_type> art_rate_types 
{
get
{
 if (_art_rate_types == null) _art_rate_types = new List<art_rate_type>();

return _art_rate_types;
}
set 
{
if ( _art_rate_types != value) 
{
_art_rate_types = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new rate_type object. 
/// </summary>
public  rate_type()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Add a new art_rate_type object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">An art_rate_type object to be added to this objects collection.</param>
public virtual void Addart_rate_type(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
// Set the Parent Property
part_rate_type.rate_type = this;
if (!part_rate_type.IsValid) { throw new Exception("part_rate_type failed on the Validate() method." + Error.ErrorsToString( part_rate_type.Validate() ) ); }
art_rate_types.Add(part_rate_type);
}

/// <summary>
/// Delete an existing art_rate_type object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">The art_rate_type object to be removed from this objects collection.</param>
public virtual void Deleteart_rate_types(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
art_rate_types.Remove(part_rate_type);
// Remove the Association with the Parent object
part_rate_type.rate_type = null;
}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

